package org.example.minebackend.mapper;

import org.apache.ibatis.annotations.*;
import org.example.minebackend.pojo.Comment;
import org.example.minebackend.pojo.Invitation;

import java.util.List;

@Mapper
public interface CommunityMapper {
    List<Invitation> getInvitations(String kind, String orderType, String content);

    @Insert("insert into invitation( `writerId`, `title`, `content`, `kind`) " +
            "values (#{writerId}, #{title},#{content}, #{kind})")
    int uploadInvitation(Invitation invitation);

    @Select("select * from invitation where id=#{id}")
    Invitation getInvitationById(Integer id);

    @Select("select * from invitationcomment where invitationId=#{id}")
    List<Comment> getAllCommentByInvitationId(Integer id);

    @Select("select * from invitationcomment where id=#{id}")
    Comment getCommentByInvitationId(Integer id);

    @Insert("insert into invitationcomment (`content`, `userId`, `invitationId`, `parentId`, `rootId`) " +
            "values (#{content}, #{userId}, #{invitationId}, #{parentId}, #{rootId})")
    int uploadComment(Comment comment);

    @Update("update invitation set nOfCollections=nOfCollections + 1 where id=#{id}")
    void addInvitationCollectionById(Integer id);

    @Insert("insert into invitationofcollection values (#{userId}, #{invitationId})")
    void insertInvitationOfCollectionById(Integer userId, Integer invitationId);

    @Select("select count(*) from invitationofcollection where userId=#{userId} and invitationId=#{invitationId}")
    Integer judgeCollection(Integer userId, Integer invitationId);

    @Update("update invitation set nOfCollections = nOfCollections - 1 where id = #{id}")
    void deleteInvitationCollectionById(Integer id);

    @Delete("delete from invitationofcollection where userId=#{userId} and invitationId=#{invitationId}")
    void deleteInvitationCollectionByTwoId(Integer userId, Integer invitationId);
}
